#include "ReturnStatement.h"
#include "../GeneralVisitor.h"

ReturnStatement::ReturnStatement(TreeNode* iReturnExpression)
{
    this->fReturnExpression = iReturnExpression;
}

ReturnStatement::~ReturnStatement()
{
    if(this->fReturnExpression != 0)
        delete this->fReturnExpression;
}

void ReturnStatement::CheckVariables(set<string>& oVariables, string iParentName)
{
    if(this->fReturnExpression != 0)
        this->fReturnExpression->CheckVariables(oVariables, iParentName);
}

void ReturnStatement::CheckFunctionCalls(set<FunctionDefinition*>& iAllFunctions, string iParentName)
{
    if(this->fReturnExpression != 0)
        this->fReturnExpression->CheckFunctionCalls(iAllFunctions, iParentName);
}

void ReturnStatement::CheckClassConstructions(set<ClassDefinition*>& iAllClasses, string iParentName)
{
    if(this->fReturnExpression != 0)
        this->fReturnExpression->CheckClassConstructions(iAllClasses, iParentName);
}

void ReturnStatement::CheckExpressionTypes(map<string, ExpressionType*>& iVarTypes, string iParentName)
{
    if(this->fReturnExpression != 0)
        this->fReturnExpression->CheckExpressionTypes(iVarTypes, iParentName);
}

ExpressionType* ReturnStatement::GetReturnType(map<string, ExpressionType*>& iVarTypes, string iParentName)
{
    if(this->fReturnExpression != 0)
        return fReturnExpression->GetType(iVarTypes, iParentName);
    else
        return new ExpressionType(Undefined, false);
}

void ReturnStatement::Accept(GeneralVisitor* iVisitor)
{
    iVisitor->Visit(this);
}

void ReturnStatement::SetReturnExpression(TreeNode* iNewExpr)
{
    if(fReturnExpression != 0)
        delete fReturnExpression;

    fReturnExpression = iNewExpr;
}
